package com.cd.university.service.impl;

import com.cd.university.service.AchievementProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 陈栋
 * @create 2021/11/3 19:31
 */
@Component
@Slf4j
public class AchievementProcessorHolder {


    /**
     * 找到Spring容器中实现了ApplyAchievementProcessor的类的bean
     */
    @Autowired
    private Map<String, AchievementProcessor> achievementProcessorMap;

    public AchievementProcessor findApplyAchievementProcessor(String type) {
        if (type==null || type.isEmpty()) {
            log.error("不存在成果形式类，或者字符串为空");
            return null;
        }

        String key = type + "Processor";
        AchievementProcessor achievementProcessor = achievementProcessorMap.get(key);

        if (achievementProcessor==null) {
            throw new RuntimeException("成果形式的处理器：" + type + "不存在");
        }

        return achievementProcessor;
    }
}
